<?php

class Banco extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->library('form_validation');
    }

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     * 		http://example.com/index.php/welcome
     * 	- or -  
     * 		http://example.com/index.php/welcome/index
     * 	- or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    public function index() {
    $this->load->helper('form'); 
        $data = array(
            "cod_b" => $this->input->post("Cod_B"),
            "deno" => $this->input->post("Deno"),
            "dir_central" => $this->input->post("Dir_Central"),            
        );
        
        $telf = array(
            "cod_b" => $this->input->post("Cod_B"),
            "num_telf" => $this->input->post("Telefono"),
        );    
        
        
        $tipo_op = $this->input->post("Operacion");
         
        switch ($tipo_op ) {
                    case "Insertar":
                    {
                        $this->form_validation->set_error_delimiters('<span class="mensaje-error">', '</span>');
                            if ($this->form_validation->run('Banco') === FALSE) {

                                $this->load->view('dbwindows/Banco');
                            } else {
                                
                                $this->load->model('BancoDB');
                                $this->BancoDB->Insert_Table($data);
                                $this->BancoDB->Insert_Table_Tel($telf);
                                $this->load->view('Clean/Banco', $data);
                            }
                    }
                        break;
                    case "Actualizar":
                    {
                        
                        $this->form_validation->set_error_delimiters('<span class="mensaje-error">', '</span>');
                            if ($this->form_validation->run('updBanco') === FALSE) {
                                $this->load->view('dbwindows/Banco');
                            } else {                                   
                            $this->load->model('bancoDB');
                            if ($this->bancoDB->update_entryban($data))
                                $this->load->view('Clean/Banco');
                            else
                                echo "Codigo no coindice, vaya atras en su navegador";    
                            }
                    }
                        break;
                    case "Eliminar":
                    {
                        
                        $borrar = array (
                    'eliminar' => $this->input->post("Cod_B"),            
                      ); // NOMBRE DEL INPUT COD o Ficha
                    
                    
                     
                    $this->form_validation->set_error_delimiters('<span class="mensaje-error">', '</span>');
                            if ($this->form_validation->run('Eliminarbanco') === FALSE) {
                                $this->load->view('dbwindows/Banco');
                            } else {
                                $this->load->model('BancoDB');     
                                    if ($this->BancoDB->borrar_tablabanco($borrar))
                                        $this->load->view('Clean/Banco',$data);
                                    else   {         
                                        echo "Ficha o Codigo inexistente en la relacion o tabla" ;
                                    ?>
                                    <br>
                                    <?php
                                        echo "Haga atras en su navegador para continuar"; 
                                    }
                            }  
                        
                    }
                        break;
                    default:
                        echo "nothing happens";
                }
        
               
    }

    

}
